﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="report_time_staff.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Accountant.report_time_staff" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <%
        try
        {
            int month = int.Parse(Request.QueryString["month"]);
            int year = int.Parse(Request.QueryString["year"]);
            foreach (TblManager admin in new TblManagerController().FetchAll().Where(x => x.Role != 1 && x.Active == true))
            {
                int hour = 0, minute = 0;
                foreach (TblCheckManager chk in new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == admin.ManagerId && DateTime.Parse(x.CheckIn.ToString()).Month == month && DateTime.Parse(x.CheckIn.ToString()).Year == year && x.Accept == true))
                {
                    if (chk.CheckOut != null)
                    {
                        if (DateTime.Parse(chk.CheckOut.ToString()).Hour >= DateTime.Parse(chk.CheckIn.ToString()).Hour)
                        {
                            hour += DateTime.Parse(chk.CheckOut.ToString()).Hour - DateTime.Parse(chk.CheckIn.ToString()).Hour;
                        }
                        else
                        {
                            hour += 24 - DateTime.Parse(chk.CheckIn.ToString()).Hour + DateTime.Parse(chk.CheckOut.ToString()).Hour;
                        }

                        if (DateTime.Parse(chk.CheckIn.ToString()).Minute <= DateTime.Parse(chk.CheckOut.ToString()).Minute)
                        {
                            minute += DateTime.Parse(chk.CheckOut.ToString()).Minute - DateTime.Parse(chk.CheckIn.ToString()).Minute;
                        }
                        else
                        {
                            minute += 60 - DateTime.Parse(chk.CheckIn.ToString()).Minute + DateTime.Parse(chk.CheckOut.ToString()).Minute;
                            hour--;
                        }
                    }
                }
                if (minute >= 60)
                {
                    int temp = minute / 60;
                    hour += temp;
                    minute = minute - (temp * 60);
                }
    %>
    <li class="w3-padding w3-row">
        <div class="w3-col l2">
            <img src="../Content/avatar/<%=admin.Avatar%>" class="w3-left w3-circle w3-margin-right" style="width: 40px; height: 40px" />
        </div>
        <div class="w3-col l6">
            <span><%=admin.FullName%></span>
        </div>
        <div class="w3-col l4">
            <span><%=hour%> giờ <%=minute%> phút</span>
        </div>
    </li>
    <%}
        }
        catch { } %>
</body>
</html>
